<template>
    <button class="l-button" :class="[`l-button--${type}`, {
        'is-plain': plain,
        'is-round': round,
        'is-circle': circle,
        'is-disabled': disabled
    }]"
    :disabled="disabled"
    @click="handleClick"
    >
        <i v-if="icon" :class="icon"></i>
        <!-- 如果没有传入任何的内容，当我们没有传入插槽的时候 -->
        <span v-if="$slots.default"><slot></slot></span>
    </button>
</template>

<script>
export default {
  name: 'LButton',
  // 封装一个通用的组件，会对props做一个约束，props进行校验
  props: {
    type: {
      // 数据类型： 字符串
      type: String,
      default: 'default'
    },
    plain: {
      type: Boolean,
      default: false
    },
    round: {
      type: Boolean,
      default: false
    },
    circle: {
      type: Boolean,
      default: false
    },
    icon: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  created () {
    // console.log(this.plain)
    // console.log(this.$slots)
    console.log(this.disabled)
  },
  methods: {
    handleClick (e) {
      // 向父组件传事件
      this.$emit('click', e)
    }
  }
}
</script>

<style lang="scss" scoped>
.l-button{
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  // 禁止元素的文字被选中
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
  &:hover,
  &:focus {
      color: #409eff;
      border-color: #c6e2ff;
      background-color: #ecf5ff;
  }
}
.l-button+.l-button {
  margin-left: 10px;
}

.l-button:active {
  color: #3a8ee6;
  border-color: #3a8ee6;
  outline: 0;
}

.l-button.is-disabled,
.l-button.is-disabled:focus,
.l-button.is-disabled:hover {
  color: #c0c4cc;
  cursor: not-allowed;
  background-image: none;
  background-color: #fff;
  border-color: #ebeef5;
}
// type样式
.l-button--primary {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
}

.l-button--primary:focus,
.l-button--primary:hover {
  background: #66b1ff;
  border-color: #66b1ff;
  color: #fff;
}

.l-button--primary.is-disabled,
.l-button--primary.is-disabled:active,
.l-button--primary.is-disabled:focus,
.l-button--primary.is-disabled:hover {
  color: #fff;
  background-color: #a0cfff;
  border-color: #a0cfff;
}
.l-button--success {
  color: #fff;
  background-color: #67c23a;
  border-color: #67c23a;
}

.l-button--success:focus,
.l-button--success:hover {
  background: #85ce61;
  border-color: #85ce61;
  color: #fff;
}

.l-button--success.is-active,
.l-button--success:active {
  background: #5daf34;
  border-color: #5daf34;
  color: #fff;
}

.l-button--success:active {
  outline: 0;
}

.l-button--success.is-disabled,
.l-button--success.is-disabled:active,
.l-button--success.is-disabled:focus,
.l-button--success.is-disabled:hover {
  color: #fff;
  background-color: #b3e19d;
  border-color: #b3e19d;
}

.l-button--warning {
  color: #fff;
  background-color: #e6a23c;
  border-color: #e6a23c;
}

.l-button--warning:focus,
.l-button--warning:hover {
  background: #ebb563;
  border-color: #ebb563;
  color: #fff;
}

.l-button--warning.is-active,
.l-button--warning:active {
  background: #cf9236;
  border-color: #cf9236;
  color: #fff;
}

.l-button--warning:active {
  outline: 0;
}

.l-button--warning.is-disabled,
.l-button--warning.is-disabled:active,
.l-button--warning.is-disabled:focus,
.l-button--warning.is-disabled:hover {
  color: #fff;
  background-color: #f3d19e;
  border-color: #f3d19e;
}

.l-button--danger {
  color: #fff;
  background-color: #f56c6c;
  border-color: #f56c6c;
}

.l-button--danger:focus,
.l-button--danger:hover {
  background: #f78989;
  border-color: #f78989;
  color: #fff;
}

.l-button--danger.is-active,
.l-button--danger:active {
  background: #dd6161;
  border-color: #dd6161;
  color: #fff;
}

.l-button--danger:active {
  outline: 0;
}

.l-button--danger.is-disabled,
.l-button--danger.is-disabled:active,
.l-button--danger.is-disabled:focus,
.l-button--danger.is-disabled:hover {
  color: #fff;
  background-color: #fab6b6;
  border-color: #fab6b6;
}
.l-button--info {
  color: #fff;
  background-color: #909399;
  border-color: #909399;
}

.l-button--info:focus,
.l-button--info:hover {
  background: #a6a9ad;
  border-color: #a6a9ad;
  color: #fff;
}

.l-button--info.is-active,
.l-button--info:active {
  background: #82848a;
  border-color: #82848a;
  color: #fff;
}

.l-button--info:active {
  outline: 0;
}

.l-button--info.is-disabled,
.l-button--info.is-disabled:active,
.l-button--info.is-disabled:focus,
.l-button--info.is-disabled:hover {
  color: #fff;
  background-color: #c8c9cc;
  border-color: #c8c9cc;
}

/**圆角**/
.l-button.is-round {
  border-radius: 20px;
  padding: 12px 23px;
}

//原形按钮
.l-button.is-circle {
    border-radius : 50%;
    padding: 12px;
}

/**size**/

.l-button--medium {
  padding: 10px 20px;
  font-size: 14px;
  border-radius: 4px;
}

.l-button--mini,
.l-button--small {
  font-size: 12px;
  border-radius: 3px;
}

.l-button--small {
  padding: 9px 15px;
  font-size: 12px;
  border-radius: 3px;
}

.l-button--mini {
  padding: 7px 15px;
  font-size: 12px;
  border-radius: 3px;
}

.l-button::-moz-focus-inner {
  border: 0;
}

/**plain 朴素的按钮**/
.l-button.is-plain {
    &:hover,
    &:focus {
        background:#fff;
        border-color:#409eff;
        color: #409eff;
    }
}
.l-button--primary.is-plain {
    color: #409eff;
    background: #ecf5ff;
    border-color:#b3d8ff;
    &:hover,
    &:focus {
        background: #489eff;
        border-color: #409eff;
        color: #fff;
    }
}
.l-button--primary.is-plain.is-disabled,
.l-button--primary.is-plain.is-disabled:active,
.l-button--primary.is-plain.is-disabled:focus,
.l-button--primary.is-plain.is-disabled:hover {
  color: #409eff;
  background: #ecf5ff;
  border-color:#b3d8ff;
}
.l-button--success.is-plain {
    color:#67c23a;
    background: #fef9eb;
    border-color: #c2e7b0;
    &:hover,
    &:focus {
        background: #67c23a;
        border-color: #67c23a;
        color:#fff;
    }
}
.l-button--success.is-plain.is-disabled,
.l-button--success.is-plain.is-disabled:active,
.l-button--success.is-plain.is-disabled:focus,
.l-button--success.is-plain.is-disabled:hover {
  color:#67c23a;
  background: #fef9eb;
  border-color: #c2e7b0;
}
.l-button--info.is-plain {
    color: #909399;
    background:#f4f4f5;
    border-color: #d3d4d6;
    &:hover,
    &:focus {
        background: #989399;
        border-color: #909399;
        color: #fff;
    }
}
.l-button--info.is-plain.is-disabled,
.l-button--info.is-plain.is-disabled:active,
.l-button--info.is-plain.is-disabled:focus,
.l-button--info.is-plain.is-disabled:hover {
  color: #909399;
  background:#f4f4f5;
  border-color: #d3d4d6;
}
.l-button--warning.is-plain {
    color: #e6a23c;
    background: #fdf6ec;
    border-color:#f5dab1;
    &:hover,
    &:focus {
        background: #e6a23c;
        border-color: #e6a23c;
        color:#fff;
    }
}
.l-button--warning.is-plain.is-disabled,
.l-button--warning.is-plain.is-disabled:active,
.l-button--warning.is-plain.is-disabled:focus,
.l-button--warning.is-plain.is-disabled:hover {
  color: #e6a23c;
  background: #fdf6ec;
  border-color:#f5dab1;
}
.l-button--danger.is-plain {
    color: #f56c6c;
    background: #feeeee;
    border-color: #fbc4c4;
    &:hover,
    &:focus {
        background: #f56c6c;
        border-color: #f56c6c;
        color: #fff;
    }
}
.l-button--danger.is-plain.is-disabled,
.l-button--danger.is-plain.is-disabled:active,
.l-button--danger.is-plain.is-disabled:focus,
.l-button--danger.is-plain.is-disabled:hover {
  color: #f56c6c;
  background: #feeeee;
  border-color: #fbc4c4;
}
</style>
